package com.yswy.backstage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yswy.backstage.service.DomainCertificateService;
import com.yswy.backstage.service.DomainService;
import com.yswy.domain.entity.Domain;
import com.yswy.domain.entity.DomainCertificate;
import com.yswy.domain.vo.dto.BaseFilter;
import com.yswy.domain.vo.gld.addOrUpate.DomainAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.DomainCertificateAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.base.BaseReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/certificate")
@Api(tags = "域名证书管理")
public class CertificateController {

    @Autowired
    private DomainCertificateService domainCertificateService;


    @GetMapping("/listCertificateByDomainId")
    @ApiOperation(value = "域名证书列表")
    public List<DomainCertificate> listCertificateByDomainId(@RequestParam(value = "domainId") Long domainId,
                                   HttpServletRequest request) {
        return domainCertificateService.listCertificateByDomainId(domainId);
    }

    @GetMapping("/isCertificateExist")
    @ApiOperation(value = "判断域名是否存在")
    public Boolean isCertificateExist(@RequestParam(value = "domainName") String domainName,
                        HttpServletRequest request) {
        return domainCertificateService.isExist(domainName);
    }

    @PostMapping("/addCertificate")
    @ApiOperation(value = "添加域名证书")
    public void addCertificate(@ModelAttribute @Validated(BaseReqVO.CREATE.class) DomainCertificateAddOrUpdate req, HttpServletRequest request) {
        domainCertificateService.addOrUpadteCertificate(req);
    }

    @PostMapping("/upadteCertificate")
    @ApiOperation(value = "修改域名证书")
    public void upadteCertificate(@ModelAttribute @Validated(BaseReqVO.UPDATE.class) DomainCertificateAddOrUpdate req, HttpServletRequest request) {
        domainCertificateService.addOrUpadteCertificate(req);
    }


    @GetMapping("/delCertificate")
    @ApiOperation(value = "删除域名证书")
    public void delCertificate(@RequestParam(value = "domainCertificateId") Long domainCertificateId,
                                   HttpServletRequest request) {
        domainCertificateService.delCertificate(domainCertificateId);
    }


}
